import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import javax.swing.JList;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.JTextField;
import java.io.*;
import java.util.*;

public class Test {

	private JFrame jFrame = null;  //  @jve:decl-index=0:visual-constraint="26,13"
	private JPanel jContentPane = null;
	private JButton jButton = null;
	private JTextField jTextField = null;
	private JList jList = null;
	private String txtField = null;
	private JList jList1 = null;
	private JButton jButton1 = null;

	/**
	 * This method initializes jFrame	
	 * 	
	 * @return javax.swing.JFrame	
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			jFrame = new JFrame();
			jFrame.setSize(new Dimension(514, 552));
			jFrame.setTitle("Test");
			jFrame.setContentPane(getJContentPane());
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJButton(), null);
			jContentPane.add(getJTextField(), null);
			jContentPane.add(getJList(), null);
			jContentPane.add(getJList1(), null);
			jContentPane.add(getJButton1(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setBounds(new Rectangle(408, 8, 85, 22));
			jButton.setText("Search");
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					ArrayList<String> searchItems = new ArrayList<String>();
					txtField = jTextField.getText();
					for(int i = 0; i < jList.getModel().getSize(); i++) {
					     String listItem = jList.getModel().getElementAt(i).toString();
					     if(listItem.startsWith(txtField)){
					    	 searchItems.add(listItem);
					     }
					 }
					jList.setListData(searchItems.toArray());
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(9, 9, 391, 21));
		}
		return jTextField;
	}

	/**
	 * This method initializes jList	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getJList() {
		if (jList == null) {
			jList = new JList();
			jList.setBounds(new Rectangle(9, 41, 485, 204));
		}
		return jList;
	}

	private void getFiles()
	{
		File dir = new File("C:/ShareFolder");
		String[] children = dir.list();
	    if (children != null) {
	    	jList.setListData(children);
	    }
	}
	
	/**
	 * This method initializes jList1	
	 * 	
	 * @return javax.swing.JList	
	 */
	private JList getJList1() {
		if (jList1 == null) {
			jList1 = new JList();
			jList1.setBounds(new Rectangle(9, 277, 485, 230));
		}
		return jList1;
	}

	/**
	 * This method initializes jButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton1() {
		if (jButton1 == null) {
			jButton1 = new JButton();
			jButton1.setBounds(new Rectangle(9, 250, 98, 21));
			jButton1.setText("Download");
		}
		return jButton1;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub\
		Test n1 = new Test();
		JFrame f1 = n1.getJFrame();
		n1.getFiles();
		f1.setVisible(true);
	}

}
